<?php
declare (strict_types=1);

namespace app\admin\controller;

use addons\BuilderPlus\components\Button;
use addons\BuilderPlus\components\Column;
use addons\BuilderPlus\components\Search;
use addons\BuilderPlus\facade\Table;

class Message extends Base
{
    public function getOptions(): array
    {
        return [
            'pk' => 'id',
            'model' => \app\common\model\Message::class,
            'with' => ['user'],
            'fast' => [
                'edit' => 'message/edit',
                'save' => '_save'
            ]
        ];
    }

    public function index(): string
    {
        return Table::init($this)
            ->setCheckbox(false)
            ->addColumns([
                ['id', 'ID', fn(Column $col) => $col->width(80)],
                ['uid', '相关会员', fn(Column $col) => $col->templet('#_userTpl')->minWidth(240)],
                ['content', '反馈内容'],
                ['status', '状态', fn(Column $col) => $col->width(100)],
                ['create_time', '反馈时间', fn(Column $col) => $col->width(150)],
                ['reply_time', '回复时间', fn(Column $col) => $col->width(150)]
            ])
            ->addRightButtons([
                'edit' => fn(Button $btn) => $btn->title("{{ !d.reply_time ? '回复' : '查看' }}")
                    ->class("{{ !d.reply_time ? 'danger' : 'normal' }}")
            ], 100)
            ->addSearch([
                ['create_time', '反馈时间', fn(Search $search) => $search->type('date')],
                ['uid', '会员编号/昵称/手机号', fn(Search $search) => $search
                    ->relation('\app\common\model\User', 'code|nickname|mobile,id')
                    ->condition('Like')],
                ['content', '反馈内容', fn(Search $search) => $search->condition('Like')]
            ])
            ->fetch();
    }
}